#include <iostream>
#include <string>

#include "test.pb.h"

using namespace std;
using namespace fixbug;

void test1()
{
    Request reqA;
    reqA.set_name("zhang san");
    reqA.set_pwd("123456");
    string str;
    // 对象数据序列化
    if (reqA.SerializeToString(&str))
    {
        cout << str << endl;
        cout << str.size() << endl;
    }

    // 对象数据序列化
    Request reqB;
    if (reqB.ParseFromString(str))
    {
        cout << reqB.name() << endl;
        cout << reqB.pwd() << endl;
    }
}

void test2()
{
    Response resp;

    // 嵌套类型的设置
    ResultCode *rc = resp.mutable_result();
    rc->set_errorno(0);
    rc->set_errormsg("");
}

void test3()
{
    GetFriendListResp resp;
    ResultCode *rc = resp.mutable_result();
    rc->set_errorno(0);

    // 设置列表
    User *user1 = resp.add_friend_list();
    user1->set_name("zhang san");
    user1->set_age(20);
    user1->set_sex(User::MAN);

    User *user2 = resp.add_friend_list();
    user2->set_name("li si");
    user2->set_age(22);
    user2->set_sex(User::WOMAN);

    cout << resp.friend_list_size() << endl;
}

int main()
{
    // test1();
    // test2();
    test3();
    return 0;
}
